﻿using BUS;
using DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BUS
{
    public class CartItem : IEquatable<CartItem>
    {
        public CartItem(int MaDienThoai)
        {
            this.ProductId = MaDienThoai;
        }
        // A place to store the quantity in the cart
        // This property has an implicit getter and setter.
        public int Quantity { get; set; }
        private DienThoaiDTO _product = null;
        private int _productId;
        public int ProductId
        {
            get { return _productId; }
            set
            {
                // To ensure that the Prod object will be re-created
                _product = null;
                _productId = value;
            }
        }
        DienThoaiBUS dtbus = new DienThoaiBUS();
        public DienThoaiDTO Prod
        {

            get
            {
                // Lazy initialization - the object won't be created until it is needed
                if (_product == null)
                {
                    _product = dtbus.LayCTDienThoai(ProductId);
                }
                return _product;
            }
        }
        public int MaDienThoai
        {
            get { return Prod.MaDienThoai; }
        }
        public string TenDienThoai
        {
            get { return Prod.TenDienThoai;  }
        }
        public string HinhDaiDien
        {
            get { return Prod.HinhDaiDien; }
        }
        public decimal Gia
        {

            get
            {
                
                    return Prod.Gia;
            }
        }
        public decimal TongCong
        {
            get
            { 
                    return Prod.Gia * Quantity;
            }

        }
        /**
	 * Equals() - Needed to implement the IEquatable interface
	 *    Tests whether or not this item is equal to the parameter
	 *    This method is called by the Contains() method in the List class
	 *    We used this Contains() method in the ShoppingCart AddItem() method
	 */
        public bool Equals(CartItem item)
        {
            return item.ProductId == this.ProductId;
        }
    }
}
